//
//  HelpLayer.m
//  
//  Source file for dealing with help layer
//

#import "HelpLayer.h"
#import "MainMenuLayer.h"
#import "GameState.h"
#import "SimpleAudioEngine.h"

static const int kHelpTitleSize = 104;


@implementation HelpLayer

// returns a scene object containing the current layer
// this essentially loads the "screen" for a
// particular section or part of the game
+(CCScene *) scene
{
	CCScene *scene = [CCScene node];
    HelpLayer *layer = [HelpLayer node];
    
	[scene addChild: layer];
	
	return scene;
}

-(void) mainMenuPressed
{
    [[CCDirector sharedDirector] replaceScene:[CCTransitionFade
                                               transitionWithDuration:0.3 scene:[MainMenuLayer scene]]];
    [[SimpleAudioEngine sharedEngine] playEffect:@"Menu_Click.wav"];
}

-(id) init
{
    if ((self = [super init])) {
        CGSize winSize = [[CCDirector sharedDirector] winSize];
        
        CCSprite *bg = [CCSprite spriteWithFile:@"menuBackground.png"];
        bg.position = ccp(winSize.width / 2, winSize.height / 2);
        [self addChild:bg z:0];
        
        CCLabelTTF *HelpTitleLbl = [CCLabelTTF labelWithString:@"Help" fontName:@"Marker Felt" fontSize:kHelpTitleSize];
        HelpTitleLbl.position = ccp(winSize.width / 2, winSize.height - kHelpTitleSize);
        HelpTitleLbl.color = ccc3(255, 255, 255);
        [self addChild:HelpTitleLbl];
        
        CCMenuItemImage *menuBtn = [CCMenuItemImage itemWithNormalImage:@"mainMenuButton.png"
                                                          selectedImage:@"mainMenuButtonHighlight.png" target:self selector:@selector(mainMenuPressed)];
        
        CCMenu *mainMenu = [CCMenu menuWithItems:menuBtn, nil];
        
        mainMenu.position = ccp(mainMenu.position.x, 50);
        [self addChild:mainMenu];
        
        // load tutorial from resource bundle
        _webView = [[UIWebView alloc] initWithFrame:CGRectMake(winSize.width / 2 - 400, winSize.height / 2 - 220, 800, 500)];

        NSString *path = [[NSBundle mainBundle] pathForResource:@"Tutorial" ofType:@"pdf"];
        NSURL *targetURL = [NSURL fileURLWithPath:path];
        NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
        [_webView loadRequest:request];
        
        [[[CCDirector sharedDirector] view] addSubview:_webView];
        
    }
    
    return self;
}

-(void)dealloc
{
    [_webView removeFromSuperview];
    [_webView release];
    [super dealloc];
}

@end
